﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebApplication.Models;

namespace WebApplication
{
    /// <summary>
    /// Summary description for Default
    /// </summary>
    public class Default : IHttpHandler
    {
        //只读变量
        private readonly string Token = "zhengshuai";
        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");

            string signature = context.Request["signature"];
            string timespan = context.Request["timestamp"];
            string nonce = context.Request["nonce"];
            string echostr = context.Request["echostr"];
            if (context.Request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timespan, nonce, Token))
                {
                    context.Response.Write(echostr);
                }
                else
                {
                    context.Response.Write("failed:" + signature + "," + CheckSignature.GetSignature(timespan, nonce, Token) + "。" + "如果你在浏览器中看到这句话，说明此地址可以被作为微信公众号后台的URL，请注意保持Token一致");
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}